<template>
  <span>
    <el-badge :value="infoCount.totalCount" class="item right-menu-item bage">
      <i @click="getWarinList" class="el-icon-message-solid" style=""></i>
    </el-badge>
  </span>


</template>

<script>
  import {
    listInfo,
    getInfo,
    delInfo,
    addInfo,
    updateInfo
  } from "@/api/lock/info";
  import waringlist from "./waringlist";
  export default {
    name: "waring",
    components: {
      waringlist
    },
    data() {
      return {
        drawer: false,
        direction: 'rtl',
        infoCount: {
          totalCount: 0
        },
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          roomId: this.roomId
        },
      };
    },
    watch: {
      'socketMsgs': {
        //处理接收到的消息
        handler: function(newValue) {
          // 判断是否是有效的日志数据
          if (newValue && newValue.data && newValue.data !== '连接成功') {
            let tar = JSON.parse(newValue.data)
            console.log("tar-----------------:",tar)
            if (tar.type === 'aTenantInsert') {
              var temp="您有一条待办消息，"+ tar.data.cellidName+"校区"+tar.data.ldidName+tar.data.lcid+'层'+tar.data.roomName +"申请人是" + tar.data.name
              this.$message.success(temp);
              this.speakText(temp);
              this.getList();
            }else if(tar.type == 1){
              var temp="您有一条故障信息需要处理";
              this.$message.success(temp);
              this.speakText(temp);
              this.getList();
            }
            // this.addLog(newValue.data);
            // this.scrollToEnd(); // 每次接收消息后滚动到底部
          }
        }
      },
      deep: true
    },
    computed: {
      socketMsgs() {
        return this.$store.state.websocket.msg;
      },
    },
    created() {
      this.$store.dispatch("webSocketInit");

      this.getList();
    },
    methods: {
      /** 查询预警信息列表 */
      getList() {
        // 使用listInfo方法获取预警信息列表
        listInfo(this.queryParams).then(response => {
          // 计算总数
          this.infoCount.totalCount = response.total || 0;
        });
      },
      handleClose(done) {
        // this.$confirm('确认关闭？')
        // 	.then(_ => {
        // 		done();
        // 	})
        // 	.catch(_ => {});
      },
      getWarinList() {
        this.$router.push({
          path: "/tenant"
          // query: {
          //   daiBanCount: this.infoCount.daiBanCount,
          //   waringCount: this.infoCount.waringCount,
          // }
        });
      },

    }
  };
</script>


<style lang="scss" scoped>
  ::v-deep .bage {
    margin-top: -40px;
    cursor: pointer;
    margin-right: 25px;
    color: #f9f0f0 !important;
    font-size: 19px !important;

    .el-badge__content {
      top: 1rem !important;
    }
  }
</style>
